home *** CD-ROM | disk | FTP | other *** search
- unit ParentAnonymousPipeUnit;
-
- interface
-
- uses
- Classes, Windows;
-
- type
- TTestAnonymousPipe = class(TThread)
- private
- FUIString: String;
- FPipeHandle: THandle;
- //Two routines to simplify showing our progress
- procedure UpdateUI;
- procedure WriteString(const S: String);
- protected
- //Body of the thread
- procedure Execute; override;
- public
- constructor Create(PipeRead: THandle);
- end;
-
- implementation
-
- uses
- ParentMainFormUnit;
-
- constructor TTestAnonymousPipe.Create(PipeRead: THandle);
- begin
- inherited Create(False);
- FPipeHandle := PipeRead;
- end;
-
- procedure TTestAnonymousPipe.UpdateUI;
- begin
- with Form1.Memo1 do
- Text := Text + FUIString;
- end;
-
- procedure TTestAnonymousPipe.WriteString(const S: String);
- begin
- FUIString := S;
- Synchronize(UpdateUI);
- end;
-
- procedure TTestAnonymousPipe.Execute;
- const
- BytesToRead = 1000;
- var
- BytesRead: DWord;
- DataBuf: array[0..BytesToRead] of Char;
- begin
- while not Terminated and
- ReadFile(FPipeHandle, DataBuf, BytesToRead, BytesRead, nil) do
- begin
- SetString(FUIString, DataBuf, BytesRead);
- Synchronize(UpdateUI);
- end;
- if not Terminated then
- WriteString('Pipe is broken')
- end;
-
- end.
-